#include <memory>
#include "TpcServer.hpp"
#include "Calculator.hpp"

Calculator calculator;
void DefaultOnMessage(std::weak_ptr<Connection> con)
{
     if(con.expired()) return;
     auto connection_ptr = con.lock();
     std::cout << connection_ptr->Inbuffer() << std::endl;
     std::string response_str = calculator.Handler(connection_ptr->Inbuffer());  // 业务逻辑简单,如果复杂,需要拿到结果单独线程处理
     if (response_str.empty())
     {
         return;
     }

     lg.logmessage(debug, "%s", response_str.c_str());
     connection_ptr->AppendOutbuff(response_str);
     //connection_ptr->_send_cb(connection_ptr); 
     auto tcpserver = connection_ptr->_tcp_server_ptr.lock();  
     tcpserver->Sender(connection_ptr);
}

int main()
{
    std::shared_ptr<TpcServer> svr(new TpcServer(DefaultOnMessage));
    svr->Init();
    svr->Loop();
    return 0;
}